package meow

import net.sf.ehcache.Element

class IconController {
  // キャッシュ
  def iconCache

  /** 大きいアイコン  */
  def view = {
    def avator = findAvator(params.username)
    if (avator) {
      response.outputStream << avator.largeIcon
    }
  }

  /** 小さいアイコン  */
  def smallView = {
    def avator = findAvator(params.username)
    if (avator) {
      response.outputStream << avator.smallIcon
    }
  }

  private findAvator(username) {
    def avator = iconCache?.get(username)?.value
    if (!avator) {
      avator = AvatorIcon.findByUsername(username)
      iconCache.put new Element(username, avator)
    }
    return avator
  }

}
